package xlj.lib.android.base.push;

import android.content.Context;
import android.util.Log;

import com.igexin.sdk.GTIntentService;
import com.igexin.sdk.message.GTCmdMessage;
import com.igexin.sdk.message.GTNotificationMessage;
import com.igexin.sdk.message.GTTransmitMessage;

import xlj.lib.android.base.utils.JsonUtil;

public class IntentService extends GTIntentService {
    @Override
    public void onReceiveServicePid(Context context, int i) {

    }

    @Override
    public void onReceiveClientId(Context context, String s) {
        if (XLPushManager.getPushManager().pushHandler != null) {
            XLPushManager.getPushManager().pushHandler.onCid(s);
        }
    }

    @Override
    public void onReceiveMessageData(Context context, GTTransmitMessage gtTransmitMessage) {
        if (XLPushManager.getPushManager().pushHandler != null) {
            XLPushManager.getPushManager().pushHandler.onReceiveMessage(gtTransmitMessage);
        }
        String str = new String(gtTransmitMessage.getPayload());
        Log.d(TAG, "payload = " + str);
        PushData pushData = JsonUtil.parse(str,PushData.class);
        NotificationPoster.post(context,pushData);
    }

    @Override
    public void onReceiveOnlineState(Context context, boolean b) {

    }

    @Override
    public void onReceiveCommandResult(Context context, GTCmdMessage gtCmdMessage) {

    }

    @Override
    public void onNotificationMessageArrived(Context context, GTNotificationMessage gtNotificationMessage) {
        if (XLPushManager.getPushManager().pushHandler != null) {
            XLPushManager.getPushManager().pushHandler.onNotificationArrived(gtNotificationMessage);
        }
    }

    @Override
    public void onNotificationMessageClicked(Context context, GTNotificationMessage gtNotificationMessage) {
        if (XLPushManager.getPushManager().pushHandler != null) {
            XLPushManager.getPushManager().pushHandler.onNotificationClicked(gtNotificationMessage);
        }
    }
}
